<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS 居中方式</title>
</head>
<style>
    *{
        margin: 0;
        padding: 0;
    }

    .parent{
        width: 100px;
        height: 100px;
        background-color: blue;
        position: relative;
        
    }
    .parent div{
        width: 50px;
        height: 50px;
        background-color: greenyellow;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%,-50%);
    }

</style>
<body>
    <div class="parent">
       <div></div>
    </div>
</body>
</html>